package http;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

/**
 * Created by Administrator on 2016/7/19.
 */
public class SocketTest {

    public static int SOCKET_PORT = 8192;

    public static void main(String[] args){
        ServerSocket s = null;
        Socket socket = null;
//        BufferedReader br = null;
//        PrintWriter pw = null;

        try {
            //设定服务端的端口号
            s = new ServerSocket(SOCKET_PORT,50);
            System.out.println("ServerSocket Start:"+s);
            System.out.println("Welcome to the server!");
            System.out.println(new Date());
            System.out.println("The server is ready!");
            while (true){
                //等待请求,此方法会一直阻塞,直到获得请求才往下走
                socket = s.accept();
                System.out.println("Connection accept socket:"+socket);
                SocketServerThread thread = new SocketServerThread(socket);
                thread.start();
            }


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
//        finally{
//            System.out.println("Close.....");
//            try {
//                br.close();
//                pw.close();
//                socket.close();
//                s.close();
//            } catch (Exception e2) {
//
//            }
//        }
    }
}
